package tgc.edu.examxy.service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import tgc.edu.examxy.custom.CommonService;
import tgc.edu.examxy.entity.ArticleManagement;
import tgc.edu.examxy.repository.ArticleManagementRepository;
import tgc.edu.examxy.web.form.AndroidArticleForm;

@Service
public class ArticleManagementService extends CommonService<ArticleManagement, UUID> {
	@Autowired
	private ArticleManagementRepository dao;
	
	public List<ArticleManagement> findByType(String string) {
		return dao.findByType(string);
	}

	public List<AndroidArticleForm> findByType(String string, Sort sort) {
		List<AndroidArticleForm> android = new ArrayList<>();
		List<ArticleManagement> findByType = dao.findByType(string,sort);
		for (ArticleManagement articleManagement : findByType) {
			AndroidArticleForm form = new AndroidArticleForm();
			form.setId(articleManagement.getId());
			form.setUpdateDate(articleManagement.getUpdateDate());
			form.setTitle(articleManagement.getTitle());
			android.add(form);
		}
		return android;
	}

	
}
